using System.Collections;
using System.Collections.Generic;

namespace OracleInternal.Common
{
	internal class SyncDictionary<K, V>
	{
		private object m_sync;

		private Dictionary<K, V> m_hashtable;

		internal int Count
		{
			get
			{
				lock (m_sync)
				{
					return m_hashtable.Count;
				}
			}
		}

		internal V this[K key]
		{
			get
			{
				lock (m_sync)
				{
					if (m_hashtable.ContainsKey(key))
					{
						return m_hashtable[key];
					}
					return default(V);
				}
			}
			set
			{
				lock (m_sync)
				{
					m_hashtable[key] = value;
				}
			}
		}

		internal SyncDictionary()
		{
			m_sync = new object();
			m_hashtable = new Dictionary<K, V>();
		}

		internal void Clear()
		{
			lock (m_sync)
			{
				m_hashtable.Clear();
			}
		}

		internal bool Remove(K k)
		{
			lock (m_sync)
			{
				return m_hashtable.Remove(k);
			}
		}

		internal bool ContainsKey(K k)
		{
			lock (m_sync)
			{
				return m_hashtable.ContainsKey(k);
			}
		}

		internal List<K> GetKeys()
		{
			lock (m_sync)
			{
				List<K> list = new List<K>(m_hashtable.Keys.Count);
				foreach (K key in m_hashtable.Keys)
				{
					list.Add(key);
				}
				return list;
			}
		}

		internal List<V> GetValues()
		{
			lock (m_sync)
			{
				List<V> list = new List<V>(m_hashtable.Values.Count);
				foreach (V value in m_hashtable.Values)
				{
					list.Add(value);
				}
				return list;
			}
		}

		public IEnumerator GetEnumerator()
		{
			return m_hashtable.GetEnumerator();
		}
	}
}
